//
//  passwordViewController.m
//  ALittleReminder
//
//  password protect private data.
//
//  Created by Arsh Bhullar on 11-11-03.
//
//  Changes:
//  Nov.1 2011 hid this view from reappearing. (George)

#import "passwordViewController.h"
#import "WhoViewController.h"

@implementation passwordViewController

@synthesize name;
@synthesize password;


-(IBAction)goAway:(id)sender{
    [sender resignFirstResponder];
    
}
-(IBAction)tapBackground:(id)sender{
    [name resignFirstResponder];
    [password resignFirstResponder];
    
}

-(IBAction)onClickClose:(id)sender{
    [self dismissModalViewControllerAnimated:YES];
}

-(IBAction)check:(id)sender{
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDir = [paths objectAtIndex: 0];
    NSString *docFile = [docDir stringByAppendingPathComponent: @"myInfo.txt"];
    
    NSString *textfromfile = [NSString stringWithContentsOfFile:docFile encoding:NSStringEncodingConversionAllowLossy error:nil];
    
    NSArray *info = [textfromfile componentsSeparatedByString:@"-"];
    
    NSString *pass  = [info objectAtIndex:5];
    
    
    
    
    NSString *passentered	= password.text;
    
    
    if([pass isEqualToString:passentered] ){
        WhoViewController *openView = [[WhoViewController alloc] initWithNibName:nil bundle:nil];
        
        UIViewController *parent = [self parentViewController];
        if(!parent) parent = [self presentingViewController];// ios 5 support
        [self dismissModalViewControllerAnimated:NO];
        [parent presentModalViewController:openView animated:NO];
    }
    
    else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Wrong Password" message:@"" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
    
    }
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
